<?php
/**
 * 执行用户相关操作
 * [ranknow bbs!] (C)2009-2015 ranknow.cn.
 *
 * @author liwei
 * @This is NOT a freeware, use is subject to license terms
 * @rcsfile $RCSfile: do_member.php,v $
 * @revision $Revision: 0.1 $
 * @date $Date: 2010/01/04 16:17:17 $
 */
require_once '../../config.inc.php';
include BBS_MDL_PATH . 'mdl_member.php';
$action = $_GET['action']?$_GET['action']:'';
dbConnect();
$ret = 'fail';
if ( $action == 'new_register' ) {
    $email = $_POST['email']?$_POST['email']:'';
    $username = $_POST['username']?$_POST['username']:'';
    $password = $_POST['password']?md5($_POST['password']):'';
    $data_member = array( 'email' => $email, 'username' => $username, 'password' => $password );
    if (add_member( $data_member )) {
      $ret = 'ok';
       set_flash( 'sysinfo', $username.'注册成功!' );
    }else{
      $ret = 'fail';
      set_flash( 'sysinfo', $username.'注册失败!' );
    }
  echo $ret;
}elseif($action=='check_member'){
  $email = $_GET['email']?$_GET['email']:'';
  $username = $_GET['username']?$_GET['username']:'';
  if (check_member_exist($username,$email)){
    set_flash( 'sysinfo', $username.'用户名或email已经存在,请使用其它用户名或email!' );
    echo '1';
  }else{
    echo '0';
  }
}elseif($action=='login'){
  $password = $_POST['password']?$_POST['password']:'';
  $username = $_POST['username']?$_POST['username']:'';
  if (login($username,$password)){
    set_flash( 'sysinfo', $username.'登录成功!' );
    echo '1';
  }else{
    set_flash( 'sysinfo', $username.'用户名或密码错误!' );
    echo '0';
  }
}elseif($action=='logout'){
  logout();
  set_flash( 'sysinfo', '您已退出论坛,将以游客身份访问论坛!' );
  header( 'Location: ' . BBS_WEB_ROOT) ;
}

dbDisconnect();
?>